package qldc.pm.tiensu.service.impl;

import java.util.ArrayList;
import java.util.List;

import qldc.pm.tiensu.NoSuchCongViecBanGiaoException;
import qldc.pm.tiensu.model.BienBanBanGiaoHoSo;
import qldc.pm.tiensu.model.CongViecBanGiao;
import qldc.pm.tiensu.model.impl.CongViecBanGiaoImpl;
import qldc.pm.tiensu.service.base.CongViecBanGiaoLocalServiceBaseImpl;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;

/**
 * The implementation of the cong viec ban giao local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link qldc.pm.tiensu.service.CongViecBanGiaoLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see qldc.pm.tiensu.service.base.CongViecBanGiaoLocalServiceBaseImpl
 * @see qldc.pm.tiensu.service.CongViecBanGiaoLocalServiceUtil
 */
public class CongViecBanGiaoLocalServiceImpl
    extends CongViecBanGiaoLocalServiceBaseImpl {
	private static Log _log = LogFactoryUtil.getLog(CongViecBanGiaoLocalServiceBaseImpl.class);

	   public CongViecBanGiao findCongViecBanGiaoId(long congViecBanGiaoId) {
		   CongViecBanGiao congViecBanGiao = null;

	    	try {
	    		congViecBanGiao = congViecBanGiaoPersistence.findByPrimaryKey(congViecBanGiaoId);
			} catch (SystemException e) {
				_log.warn(e.getMessage());
			} catch (NoSuchCongViecBanGiaoException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	    	return congViecBanGiao;
	    }
	public CongViecBanGiao addCongViec(long bienBanBanGiaoId, String tenCongViec, String tienDoThucHien, String chuThich) throws SystemException{
		long congViecBanGiaoId = counterLocalService.increment(CongViecBanGiao.class.getName());
		CongViecBanGiao congViecBanGiao = createCongViecBanGiao(congViecBanGiaoId);
		
		congViecBanGiao.setBienBanBanGiaoHoSoId(bienBanBanGiaoId);
		congViecBanGiao.setTenCongViec(tenCongViec);
		congViecBanGiao.setTienDoThucHien(tienDoThucHien);
		congViecBanGiao.setChuThich(chuThich);    	
    	
    	return addCongViecBanGiao(congViecBanGiao);
	}
	public CongViecBanGiao updateCongViec(long congViecBanGiaoId, long bienBanBanGiaoId, String tenCongViec, String tienDoThucHien, String chuThich) throws SystemException{
		CongViecBanGiao congViecBanGiao = findCongViecBanGiaoId(congViecBanGiaoId);
		if (Validator.isNotNull(congViecBanGiao)){
			congViecBanGiao.setBienBanBanGiaoHoSoId(bienBanBanGiaoId);
			congViecBanGiao.setTenCongViec(tenCongViec);
			congViecBanGiao.setTienDoThucHien(tienDoThucHien);
			congViecBanGiao.setChuThich(chuThich);    	
		}
    	return updateCongViecBanGiao(congViecBanGiao);
	}
	public List<CongViecBanGiao> findByBienBanBanGiaoId(long bienBanBanGiaoId){
		List<CongViecBanGiao> result = new ArrayList<CongViecBanGiao>();
		try {
			result = congViecBanGiaoPersistence.findByBienBanBanGiaoHoSoId(bienBanBanGiaoId);
		} catch (SystemException e) {
			System.out.println("Not found ");
		}
		return result;
	}
	
}
